package com.mmall.controller;

import com.mmall.annotation.RequsetPremission;
import com.mmall.common.JsonData;
import com.mmall.param.DeptParam;
import com.mmall.service.SysDeptService;
import com.mmall.service.SysTreeService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

@Controller
@RequestMapping("/sys/dept")
@RequsetPremission(state = true,permissionName = "部门管理",url="/sys/dept")
public class SysDeptController {
    @Resource
    private SysDeptService sysDeptService;
    @Resource
    private SysTreeService sysTreeService;

    @RequestMapping("/save.json")
    @ResponseBody
    @RequsetPremission(state = true,permissionName = "保存部门",url="/save.json")
    public JsonData saveDept(DeptParam param){
        sysDeptService.save(param);
        return  JsonData.success();
    }

    @RequestMapping("/dept.page")
    @RequsetPremission(state = true,permissionName = "进入部门管理界面",url="/dept.page")
    public ModelAndView page(){
        return new ModelAndView("dept");
    }

    @RequestMapping("/tree.json")
    @ResponseBody
    @RequsetPremission(state = true,permissionName = "部门树展示",url="/tree.json")
    public JsonData tree(){
     return JsonData.success(sysTreeService.deptTree());
    }

    @RequestMapping("/update.json")
    @ResponseBody
    @RequsetPremission(state = true,permissionName = "更新部门",url="/update.json")
    public JsonData updateDept(DeptParam param){
        sysDeptService.update(param);
        return  JsonData.success();
    }

    @RequestMapping("/delete.json")
    @ResponseBody
    @RequsetPremission(state = true,permissionName = "删除",url="/delete.json")
    public JsonData deleteDept(Integer id){
        sysDeptService.delete(id);
        return  JsonData.success();
    }
}
